
	<div id="action" class="easyui-dialog" closed="true" style="display:none;">
		<form class="easyui-form">
			<table>

				<tr id="seeS">
					<td>选择小区：</td>
					<td>
						<button onClick='seeS()'>选择小区</button>
					</td>
				</tr>

				<tr>
					<td>小区名称显示：</td>
					<td>
						<input type="text" id="cellName" disabled="disabled" style="float: left;">
					</td>
				</tr>

				<tr>
					<td>栋名称：</td>
					<td>
						<input name='buildingName' id="buildingName" type="text" placeholder="输入栋名称">如：2栋、8栋
					</td>
				</tr>

				<tr>
					<td>栋建筑楼层：</td>
					<td>
						<input name='buildingFloor' id="buildingFloor" type="text" placeholder="输入栋建筑楼层">如：20层楼、10层楼
					</td>
				</tr>

				<!-- <tr>
					<td>栋结构：</td>
					<td>
						<input name='structure' id="structure" type="text" placeholder="输入栋结构">类别：多层建筑、高层建筑、其他
					</td>
				</tr>
				 -->

				<tr>
					<td>栋结构：</td>
					<td>
						<select name="structure" id="structure">
							<option value="多层建筑">多层建筑</option>
							<option value="高层建筑">高层建筑</option>
							<option value="其他">其他</option>
						</select>
					</td>
				</tr>

				<tr>
					<td>栋配套设施：</td>
					<td>
						<input id="elevator" name="elevator" type="checkbox" value="elevator" />电梯
						<input id="parkingLot" name="parkingLot" type="checkbox" value="parkingLot" />停车场
					</td>
				</tr>

				<tr>
					<td>栋描述：</td>
					<td>
						<textarea name="describe" class="describe" style="width:75%;height:100px"></textarea>
					</td>
				</tr>

				<tr>
					<td>栋图片上传：</td>
					<td>
						<div>
							<input name='pic' id='pic' type="file" onchange="product.upPicMany(this)">
						</div>
					</td>
				</tr>

				<tr>
					<td>栋图片显示：</td>
					<td>
						<div id="picChild"></div>
					</td>
				</tr>

				<input type="hidden" id="smallAreaID">
				<input type="hidden" name="id" id='id'>

			</table>
		</form>

	</div>

	<script type="text/javascript">

		// 设置文本编辑器KindEditor
        KindEditor.ready(function(K) {

    		window.describe = K.create('.describe', {
            	uploadJson : '/ServicePic/picSave?dir=image'
            });
        });

		function submit(id){

			var method = "/daoBuilding/buildingAdd";
			if(id > 0){
				var method = "/daoBuilding/buildingSaveData";
			}

			var smallAreaID = $("#smallAreaID").val();
	        var buildingName = $("#buildingName").val();
	        var buildingFloor = $("#buildingFloor").val();
	        var structure = $("#structure").val();

			// 多选
			var elevator = $("#elevator")[0].checked;
			var parkingLot = $("#parkingLot")[0].checked;
			var checked = new Array();
			checked = {
				"elevator":elevator,
				"parkingLot":parkingLot,
			}
			var supportingFacilities  = JSON.stringify(checked);

	        var describeTemporary = describe.html();

			// 图片上次错误提示
			picUrl = $('#picChild img').attr('src');
			/*if(picUrl == undefined){
				$.messager.alert('提示信息', "请上传多图片");
				return;
			}*/
			// 图片上传数据组合
			var picImg = new Array();
			$('.picImg').each(function(i, n){
				var src = $(this).attr('src');
				var savename = $(this).attr('savename');
				picImg[i] = {
					"firstPictureId":i,
					"firstPictureFileName":savename,
					"firstPictureAddress":src,
				}
			});
			var picture  = JSON.stringify(picImg);

	        $.messager.progress({msg:'正在增加...',interval:3000,});
			$.ajax({
				type:"post",
				url:method,
				data:{
					smallAreaID:smallAreaID,
					buildingName:buildingName,
					buildingFloor:buildingFloor,
					structure:structure,
					supportingFacilities:supportingFacilities,
					describe:describeTemporary,
					picture:picture,
					id:id,
				},
				cache: false,
				dataType:'html',
				success:function(data){

					var data = eval('('+data+')');
					if( data.info == 'success' ){
						
						$.messager.progress('close');
						$('#action').dialog('close');
						$('#data').datagrid('reload');
					} else {
						
						$.messager.progress('close');
						$.messager.alert('提示信息', data.info);
					}
				}
			});
		}

		function doAdd(id, data){

			$("#action form").form('reset');
			$("#picChild").html('');
			describe.html('');

			var title = '新增';

			$("#seeS").show();	// 171021. 判断重复值，选择的方案，无法关系两张表问题，最后只能选择关系一张表问题

			if(id > 0){
				var title = '修改';

				$("#seeS").hide(); // 171021. 判断重复值，选择的方案，无法关系两张表问题，最后只能选择关系一张表问题

				$("#cellName").val(data.cellName);
				$("#smallAreaID").val(data.smallAreaID);
				$("#buildingName").val(data.buildingName);
				$("#buildingFloor").val(data.buildingFloor);
				$("#structure").val(data.structure);

				// 多选
				var supportingFacilities = jQuery.parseJSON(data.supportingFacilities);
				if(supportingFacilities.elevator){
					$("#elevator").attr("checked",true);
				}else{
					$("#elevator").attr("checked",false);
				}
				if(supportingFacilities.parkingLot){
					$("#parkingLot").attr("checked",true);
				}else{
					$("#parkingLot").attr("checked",false);
				}

				describe.html(data.describe);

				// 多图
				var picture = jQuery.parseJSON(data.picture);
				for (var i = 0; i < picture.length; i++) {
					var productAddress = picture[i].firstPictureAddress;
					var productFileName = picture[i].firstPictureFileName;
					$('#picChild').append("<div class='picShowWrap' style='width:100px;height:100px;position:relative;display:inline-block;float:left;'>"
											+"<img class='picImg' width='100' height='100' src='"+productAddress+"' savename='"+productFileName+"'/>"
											+"<button onclick='product.movePicMany(this)' style='position: absolute;left:0px;bottom:0px'>左移</button>"
											+"<button onclick='product.removePic(this)' style='position: absolute;right:0px;bottom:0px'>删除</button>"
											+"</div>");
				}

				$("#id").val(data.id);

			}else{
				// authority.list();
			}

			$('#action').show();
			$('#action').dialog('open').dialog({
				title:title,    
				width:"100%",    
				height:"100%",
				closed:false,    
				cache:false,    
				modal:true,
				closable:true, 
				left:0,
				top:0,
				buttons:[{
					text:'确定',
					width:'56',
					handler:function(){

						submit(id);
					}
				},{
					text:'取消',
					width:'56',
					handler:function(){

						$('#action').dialog('close');
					}
				}],
			});
		}

		// 父窗口关闭弹框方法
        function parentWindowClosed(id, cellName) {

        	$("#smallAreaID").val(id);
        	$("#cellName").val(cellName);
        	
            $("#bombBox").dialog("close");
            $('#data').datagrid('reload');   
        }

		// 弹框方法
		function seeS(id){

			var url = '/adminBuilding/adminBuildingAddSmallArea';
			var content = '<iframe id="iframeBombBox" scrolling="auto" frameborder="0" src="'
						+ url + '" style="width:100%;height:100%;"></iframe>';
			$('#bombBox').dialog({
			    title: '用户',
			    width: '100%',
			    height: '100%',
			    modal: true,
			    content: content,
			    scroll: false,
			}); 
		}

	</script>
